package com.lp.search.controller;

import com.lp.model.config.AppResult;
import com.lp.model.config.CodeMsg;
import com.lp.model.dto.search.SearchPageDto;
import com.lp.model.entity.article.vo.PageVO;
import com.lp.model.entity.user.User;
import com.lp.model.utils.PageUtils;
import com.lp.search.service.IUserSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserSearchController {

    @Autowired
    private IUserSearchService userSearchService;

    @PostMapping("/all")
    public AppResult search(@RequestBody SearchPageDto pageDto) {
        if(!PageUtils.checkSearchPageDto(pageDto)) {
            return AppResult.fail(CodeMsg.FAIL_ERROR_SEARCH_PAGE);
        }
        PageVO<User> userPageVO = userSearchService.search(pageDto);
        return AppResult.success(userPageVO);
    }

}
